/*
* Globals.java
* Copyright (C) 2003
* 
* $Id: Globals.java,v 1.5 2005/02/07 17:49:26 cawe Exp $
*/
/*
Copyright (C) 1997-2001 Id Software, Inc.

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/
using System;
using System.IO;
using Suake2.UI.client;
using Suake2.UI.game;
using Suake2.UI.qcommon;
using Suake2.UI.render;

namespace Suake2.UI
{
    /// <summary> Globals ist the collection of global variables and constants.
    /// It is more elegant to use these vars by inheritance to separate 
    /// it with eclipse refactoring later.
    /// 
    /// As consequence you dont have to touch that much code this time. 
    /// </summary>
    public class Globals : Defines
    {
        public const String __DATE__ = "2003";

        public const String BASEDIRNAME = "baseq2";
        public const float VERSION = 3.21f;

        public static readonly float[][] bytedirs = new[]
                                                        {
                                                            new[] {- 0.525731f, 0.000000f, 0.850651f},
                                                            new[] {- 0.442863f, 0.238856f, 0.864188f},
                                                            new[] {- 0.295242f, 0.000000f, 0.955423f},
                                                            new[] {- 0.309017f, 0.500000f, 0.809017f},
                                                            new[] {- 0.162460f, 0.262866f, 0.951056f},
                                                            new[] {0.000000f, 0.000000f, 1.000000f},
                                                            new[] {0.000000f, 0.850651f, 0.525731f},
                                                            new[] {- 0.147621f, 0.716567f, 0.681718f},
                                                            new[] {0.147621f, 0.716567f, 0.681718f},
                                                            new[] {0.000000f, 0.525731f, 0.850651f},
                                                            new[] {0.309017f, 0.500000f, 0.809017f},
                                                            new[] {0.525731f, 0.000000f, 0.850651f},
                                                            new[] {0.295242f, 0.000000f, 0.955423f},
                                                            new[] {0.442863f, 0.238856f, 0.864188f},
                                                            new[] {0.162460f, 0.262866f, 0.951056f},
                                                            new[] {- 0.681718f, 0.147621f, 0.716567f},
                                                            new[] {- 0.809017f, 0.309017f, 0.500000f},
                                                            new[] {- 0.587785f, 0.425325f, 0.688191f},
                                                            new[] {- 0.850651f, 0.525731f, 0.000000f},
                                                            new[] {- 0.864188f, 0.442863f, 0.238856f},
                                                            new[] {- 0.716567f, 0.681718f, 0.147621f},
                                                            new[] {- 0.688191f, 0.587785f, 0.425325f},
                                                            new[] {- 0.500000f, 0.809017f, 0.309017f},
                                                            new[] {- 0.238856f, 0.864188f, 0.442863f},
                                                            new[] {- 0.425325f, 0.688191f, 0.587785f},
                                                            new[] {- 0.716567f, 0.681718f, - 0.147621f},
                                                            new[] {- 0.500000f, 0.809017f, - 0.309017f},
                                                            new[] {- 0.525731f, 0.850651f, 0.000000f},
                                                            new[] {0.000000f, 0.850651f, - 0.525731f},
                                                            new[] {- 0.238856f, 0.864188f, - 0.442863f},
                                                            new[] {0.000000f, 0.955423f, - 0.295242f},
                                                            new[] {- 0.262866f, 0.951056f, - 0.162460f},
                                                            new[] {0.000000f, 1.000000f, 0.000000f},
                                                            new[] {0.000000f, 0.955423f, 0.295242f},
                                                            new[] {- 0.262866f, 0.951056f, 0.162460f},
                                                            new[] {0.238856f, 0.864188f, 0.442863f},
                                                            new[] {0.262866f, 0.951056f, 0.162460f},
                                                            new[] {0.500000f, 0.809017f, 0.309017f},
                                                            new[] {0.238856f, 0.864188f, - 0.442863f},
                                                            new[] {0.262866f, 0.951056f, - 0.162460f},
                                                            new[] {0.500000f, 0.809017f, - 0.309017f},
                                                            new[] {0.850651f, 0.525731f, 0.000000f},
                                                            new[] {0.716567f, 0.681718f, 0.147621f},
                                                            new[] {0.716567f, 0.681718f, - 0.147621f},
                                                            new[] {0.525731f, 0.850651f, 0.000000f},
                                                            new[] {0.425325f, 0.688191f, 0.587785f},
                                                            new[] {0.864188f, 0.442863f, 0.238856f},
                                                            new[] {0.688191f, 0.587785f, 0.425325f},
                                                            new[] {0.809017f, 0.309017f, 0.500000f},
                                                            new[] {0.681718f, 0.147621f, 0.716567f},
                                                            new[] {0.587785f, 0.425325f, 0.688191f},
                                                            new[] {0.955423f, 0.295242f, 0.000000f},
                                                            new[] {1.000000f, 0.000000f, 0.000000f},
                                                            new[] {0.951056f, 0.162460f, 0.262866f},
                                                            new[] {0.850651f, - 0.525731f, 0.000000f},
                                                            new[] {0.955423f, - 0.295242f, 0.000000f},
                                                            new[] {0.864188f, - 0.442863f, 0.238856f},
                                                            new[] {0.951056f, - 0.162460f, 0.262866f},
                                                            new[] {0.809017f, - 0.309017f, 0.500000f},
                                                            new[] {0.681718f, - 0.147621f, 0.716567f},
                                                            new[] {0.850651f, 0.000000f, 0.525731f},
                                                            new[] {0.864188f, 0.442863f, - 0.238856f},
                                                            new[] {0.809017f, 0.309017f, - 0.500000f},
                                                            new[] {0.951056f, 0.162460f, - 0.262866f},
                                                            new[] {0.525731f, 0.000000f, - 0.850651f},
                                                            new[] {0.681718f, 0.147621f, - 0.716567f},
                                                            new[] {0.681718f, - 0.147621f, - 0.716567f},
                                                            new[] {0.850651f, 0.000000f, - 0.525731f},
                                                            new[] {0.809017f, - 0.309017f, - 0.500000f},
                                                            new[] {0.864188f, - 0.442863f, - 0.238856f},
                                                            new[] {0.951056f, - 0.162460f, - 0.262866f},
                                                            new[] {0.147621f, 0.716567f, - 0.681718f},
                                                            new[] {0.309017f, 0.500000f, - 0.809017f},
                                                            new[] {0.425325f, 0.688191f, - 0.587785f},
                                                            new[] {0.442863f, 0.238856f, - 0.864188f},
                                                            new[] {0.587785f, 0.425325f, - 0.688191f},
                                                            new[] {0.688191f, 0.587785f, - 0.425325f},
                                                            new[] {- 0.147621f, 0.716567f, - 0.681718f},
                                                            new[] {- 0.309017f, 0.500000f, - 0.809017f},
                                                            new[] {0.000000f, 0.525731f, - 0.850651f},
                                                            new[] {- 0.525731f, 0.000000f, - 0.850651f},
                                                            new[] {- 0.442863f, 0.238856f, - 0.864188f},
                                                            new[] {- 0.295242f, 0.000000f, - 0.955423f},
                                                            new[] {- 0.162460f, 0.262866f, - 0.951056f},
                                                            new[] {0.000000f, 0.000000f, - 1.000000f},
                                                            new[] {0.295242f, 0.000000f, - 0.955423f},
                                                            new[] {0.162460f, 0.262866f, - 0.951056f},
                                                            new[] {- 0.442863f, - 0.238856f, - 0.864188f},
                                                            new[] {- 0.309017f, - 0.500000f, - 0.809017f},
                                                            new[] {- 0.162460f, - 0.262866f, - 0.951056f},
                                                            new[] {0.000000f, - 0.850651f, - 0.525731f},
                                                            new[] {- 0.147621f, - 0.716567f, - 0.681718f},
                                                            new[] {0.147621f, - 0.716567f, - 0.681718f},
                                                            new[] {0.000000f, - 0.525731f, - 0.850651f},
                                                            new[] {0.309017f, - 0.500000f, - 0.809017f},
                                                            new[] {0.442863f, - 0.238856f, - 0.864188f},
                                                            new[] {0.162460f, - 0.262866f, - 0.951056f},
                                                            new[] {0.238856f, - 0.864188f, - 0.442863f},
                                                            new[] {0.500000f, - 0.809017f, - 0.309017f},
                                                            new[] {0.425325f, - 0.688191f, - 0.587785f},
                                                            new[] {0.716567f, - 0.681718f, - 0.147621f},
                                                            new[] {0.688191f, - 0.587785f, - 0.425325f},
                                                            new[] {0.587785f, - 0.425325f, - 0.688191f},
                                                            new[] {0.000000f, - 0.955423f, - 0.295242f},
                                                            new[] {0.000000f, - 1.000000f, 0.000000f},
                                                            new[] {0.262866f, - 0.951056f, - 0.162460f},
                                                            new[] {0.000000f, - 0.850651f, 0.525731f},
                                                            new[] {0.000000f, - 0.955423f, 0.295242f},
                                                            new[] {0.238856f, - 0.864188f, 0.442863f},
                                                            new[] {0.262866f, - 0.951056f, 0.162460f},
                                                            new[] {0.500000f, - 0.809017f, 0.309017f},
                                                            new[] {0.716567f, - 0.681718f, 0.147621f},
                                                            new[] {0.525731f, - 0.850651f, 0.000000f},
                                                            new[] {- 0.238856f, - 0.864188f, - 0.442863f},
                                                            new[] {- 0.500000f, - 0.809017f, - 0.309017f},
                                                            new[] {- 0.262866f, - 0.951056f, - 0.162460f},
                                                            new[] {- 0.850651f, - 0.525731f, 0.000000f},
                                                            new[] {- 0.716567f, - 0.681718f, - 0.147621f},
                                                            new[] {- 0.716567f, - 0.681718f, 0.147621f},
                                                            new[] {- 0.525731f, - 0.850651f, 0.000000f},
                                                            new[] {- 0.500000f, - 0.809017f, 0.309017f},
                                                            new[] {- 0.238856f, - 0.864188f, 0.442863f},
                                                            new[] {- 0.262866f, - 0.951056f, 0.162460f},
                                                            new[] {- 0.864188f, - 0.442863f, 0.238856f},
                                                            new[] {- 0.809017f, - 0.309017f, 0.500000f},
                                                            new[] {- 0.688191f, - 0.587785f, 0.425325f},
                                                            new[] {- 0.681718f, - 0.147621f, 0.716567f},
                                                            new[] {- 0.442863f, - 0.238856f, 0.864188f},
                                                            new[] {- 0.587785f, - 0.425325f, 0.688191f},
                                                            new[] {- 0.309017f, - 0.500000f, 0.809017f},
                                                            new[] {- 0.147621f, - 0.716567f, 0.681718f},
                                                            new[] {- 0.425325f, - 0.688191f, 0.587785f},
                                                            new[] {- 0.162460f, - 0.262866f, 0.951056f},
                                                            new[] {0.442863f, - 0.238856f, 0.864188f},
                                                            new[] {0.162460f, - 0.262866f, 0.951056f},
                                                            new[] {0.309017f, - 0.500000f, 0.809017f},
                                                            new[] {0.147621f, - 0.716567f, 0.681718f},
                                                            new[] {0.000000f, - 0.525731f, 0.850651f},
                                                            new[] {0.425325f, - 0.688191f, 0.587785f},
                                                            new[] {0.587785f, - 0.425325f, 0.688191f},
                                                            new[] {0.688191f, - 0.587785f, 0.425325f},
                                                            new[] {- 0.955423f, 0.295242f, 0.000000f},
                                                            new[] {- 0.951056f, 0.162460f, 0.262866f},
                                                            new[] {- 1.000000f, 0.000000f, 0.000000f},
                                                            new[] {- 0.850651f, 0.000000f, 0.525731f},
                                                            new[] {- 0.955423f, - 0.295242f, 0.000000f},
                                                            new[] {- 0.951056f, - 0.162460f, 0.262866f},
                                                            new[] {- 0.864188f, 0.442863f, - 0.238856f},
                                                            new[] {- 0.951056f, 0.162460f, - 0.262866f},
                                                            new[] {- 0.809017f, 0.309017f, - 0.500000f},
                                                            new[] {- 0.864188f, - 0.442863f, - 0.238856f},
                                                            new[] {- 0.951056f, - 0.162460f, - 0.262866f},
                                                            new[] {- 0.809017f, - 0.309017f, - 0.500000f},
                                                            new[] {- 0.681718f, 0.147621f, - 0.716567f},
                                                            new[] {- 0.681718f, - 0.147621f, - 0.716567f},
                                                            new[] {- 0.850651f, 0.000000f, - 0.525731f},
                                                            new[] {- 0.688191f, 0.587785f, - 0.425325f},
                                                            new[] {- 0.587785f, 0.425325f, - 0.688191f},
                                                            new[] {- 0.425325f, 0.688191f, - 0.587785f},
                                                            new[] {- 0.425325f, - 0.688191f, - 0.587785f},
                                                            new[] {- 0.587785f, - 0.425325f, - 0.688191f},
                                                            new[] {- 0.688191f, - 0.587785f, - 0.425325f}
                                                        };

        public static readonly console_t con = new console_t();

        /*
		* global variables
		*/

        public static int alias_count;
        public static int c_brush_traces;
        public static int c_pointcontents;
        public static int c_traces;
        public static String chat_buffer = "";
        public static int chat_bufferlen;
        public static bool chat_team;
        public static client_state_t cl = new client_state_t();

        public static cvar_t cl_add_blend;
        public static cvar_t cl_add_entities;
        public static cvar_t cl_add_lights;
        public static cvar_t cl_add_particles;
        public static cvar_t cl_anglespeedkey;
        public static cvar_t cl_autoskins;
        public static centity_t[] cl_entities;
        public static cvar_t cl_footsteps;
        public static cvar_t cl_forwardspeed;
        public static cvar_t cl_gun;
        public static cvar_t cl_lightlevel;
        public static cvar_t cl_maxfps;
        public static cvar_t cl_noskins;
        public static entity_state_t[] cl_parse_entities;
        public static cvar_t cl_paused;
        public static cvar_t cl_pitchspeed;
        public static cvar_t cl_predict;
        public static cvar_t cl_run;
        public static cvar_t cl_showclamp;
        public static cvar_t cl_showmiss;
        public static cvar_t cl_shownet;
        public static cvar_t cl_sidespeed;
        public static cvar_t cl_stereo;
        public static cvar_t cl_stereo_separation;
        public static cvar_t cl_timedemo = new cvar_t();
        public static cvar_t cl_timeout;
        public static cvar_t cl_upspeed;
        public static cvar_t cl_vwep;
        public static cvar_t cl_yawspeed;
        public static client_static_t cls = new client_static_t();
        public static cmdalias_t cmd_alias;
        public static sizebuf_t cmd_text = new sizebuf_t();
        public static sbyte[] cmd_text_buf = new sbyte[8192];
        public static bool cmd_wait;
        public static cvar_t con_notifytime;
        public static cvar_t crosshair;
        public static int curtime;
        public static cvar_t cvar_vars;
        public static cvar_t dedicated;
        public static sbyte[] defer_text_buf = new sbyte[8192];
        public static cvar_t developer;
        public static int edit_line;
        public static cvar_t fixedtime;
        public static cvar_t fov;
        public static cvar_t freelook;
        public static cvar_t gender;
        public static cvar_t gender_auto;
        public static int gun_frame;
        public static model_t gun_model;
        public static cvar_t hand;
        public static cvar_t host_speeds;
        public static cvar_t in_joystick;
        public static cvar_t in_mouse;
        public static cvar_t info_password;
        public static cvar_t info_spectator;
        public static int key_linepos;
        public static sbyte[][] key_lines = new sbyte[32][];
        public static String[] keybindings = new String[256];
        public static bool[] keydown = new bool[256];
        public static cvar_t log_stats;
        public static StreamWriter log_stats_file;
        public static FileStream logfile;
        public static cvar_t logfile_active;
        public static cvar_t lookspring;
        public static cvar_t lookstrafe;
        public static cvar_t m_filter;
        public static cvar_t m_forward;
        public static cvar_t m_pitch;
        public static cvar_t m_side;
        public static cvar_t m_yaw;
        public static cvar_t msg;

        public static cvar_t name;
        public static netadr_t net_from = new netadr_t();
        public static sizebuf_t net_message = new sizebuf_t();
        public static sbyte[] net_message_buffer = new sbyte[MAX_MSGLEN];
        public static cvar_t nostdout;
        public static cvar_t rate;
        public static cvar_t rcon_address;
        public static cvar_t rcon_client_password;

        // Renderer interface used by VID, SCR, ...
        public static refexport_t re = new DummyRenderer();
        public static Random rnd = new Random();

        public static vrect_t scr_vrect = new vrect_t();
        public static cvar_t sensitivity;
        public static int server_state;
        public static cvar_t showtrace;
        public static cvar_t skin;
        public static int sys_frame_time;
        public static int time_after_game;
        public static int time_after_ref;
        public static int time_before_game;
        public static int time_before_ref;
        public static cvar_t timescale;
        public static bool userinfo_modified;

        public static float[] vec3_origin = new[] {0.0f, 0.0f, 0.0f};
        public static viddef_t viddef = new viddef_t();

        public static int vidref_val = VIDREF_GL;

        static Globals()
        {
            cl_entities = new centity_t[MAX_EDICTS];
            {
                for (int i = 0; i < cl_entities.Length; i++)
                {
                    cl_entities[i] = new centity_t();
                }
            }
            cl_parse_entities = new entity_state_t[MAX_PARSE_ENTITIES];
            {
                for (int i = 0; i < cl_parse_entities.Length; i++)
                {
                    cl_parse_entities[i] = new entity_state_t(null);
                }
            }
            {
                for (int i = 0; i < key_lines.Length; i++)
                    key_lines[i] = new sbyte[MAXCMDLINE];
            }
        }

        public Globals()
        {
            InitBlock();
        }

        private void InitBlock()
        {
            // comentario de HZ: se inicializan mas abajo
            //cl_entities = ;
            //cl_parse_entities = ;
        }
    }
}